package app.system.controll;

import app.system.entity.SysComment;
import app.system.entity.SysUser;
import app.system.service.SysCommentService;
import app.utils.Result.AjaxResult;
import app.utils.SoleID;
import app.utils.VeDate;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class SysCommentControll {
    @Autowired
    private SysCommentService sysCommentService;

    @PostMapping("saveComment")
    public AjaxResult saveComment(@RequestBody SysComment sysComment){
        SysUser sysUser = (SysUser) SecurityUtils.getSubject().getPrincipal();
        if (sysUser == null){
            return AjaxResult.success("您尚未登录");
        }else {
            sysComment.setComment_id(SoleID.getId());
            sysComment.setComment_userid(sysUser.getUser_id());
            sysComment.setComment_date(VeDate.dateToStrLong(new Date()));
            sysCommentService.saveComment(sysComment);
            return AjaxResult.success("评论成功");
        }
    }
}
